import MainContainerCustom from '@/components/MainContainerCustom';
import { View } from '@tarojs/components';
import { useEffect, useState } from 'react';
import { getProTable } from '@/mock/example';
import { usePullDownRefresh, useReachBottom } from '@tarojs/taro';
import Taro from '@tarojs/taro';
// import { PullToRefresh } from '@antmjs/vantui';

export default function DemoList() {
  const [loadData, setLoadData] = useState<any>([]);
  // const [loadRequestParams, setLoadRequestParams] = useState<any>({});

  useEffect(() => {
    // setTimeout(() => {
    //   setLoadRequestParams({ id: 1 });
    // }, 10000);
    getProTable({ page: 1 }).then((res: any) => {
      setLoadData([...res.data.data]);
    });
  }, []);

  const onRefresh = async () => {
    // Taro.startPullDownRefresh();
    try {
      const res = await getProTable({ page: 1 });
      setLoadData([...res.data.data]);
      Taro.stopPullDownRefresh();
    } catch (error) {}
    return undefined;
  };
  useReachBottom(() => {
    // Taro.startPullDownRefresh();
    getProTable({ page: 2 }).then((res: any) => {
      console.log(res);
      const newData: any = [...loadData, ...res.data.data];
      setLoadData(newData);
      // Taro.startPullDownRefresh();
    });
  });

  usePullDownRefresh(() => {
    onRefresh();
  });

  console.log(loadData);

  return (
    <MainContainerCustom
    // pageSize={10}
    // loadMore={false}
    // loadData={loadData}
    // setLoadData={setLoadData}
    // loadRequest={getProTable}
    // loadRequestParams={loadRequestParams}
    // enablePullDownRefresh={true}
    >
      {/* <PullToRefresh onRefresh={onRefresh} touchMaxStart={600}>
        {loadData.map((item: any) => {
          return (
            <View key={item.id}>
              <View> 为Taro而设计的Hooks Library</View>
              <View> asdasdasdasdas Library</View>
              <View>
                {item.id}-{item.title}
              </View>
              <View> {item.description}</View>
            </View>
          );
        })}
      </PullToRefresh> */}
      {loadData.map((item: any) => {
        return (
          <View key={item.id}>
            <View> 为Taro而设计的Hooks Library</View>
            <View> asdasdasdasdas Library</View>
            <View>
              {item.id}-{item.title}
            </View>
            <View> {item.description}</View>
          </View>
        );
      })}
    </MainContainerCustom>
  );
}
